#include <stdio.h>

//https://www.nowcoder.com/practice/bb66c27cb7aa48f9ba7d9f88e4068285?tpId=290&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D290

int main() {
    int num = 0;
    int F = 0;
    int loc = 1;
    int cnt = 0;
    scanf("%d%d", &num, &F);
    while(loc <= num) {
        int left = num / loc / 10;
        int right = num % loc;
        int cur = num / loc % 10;
        if (F) {
            cnt += left * loc;
        }
        if (!F && left) {
            cnt += (left - 1) * loc;
        }
        if (cur > F && (F || left)) {
            cnt += loc;
        }
        if (cur == F && (F || left)) {
            cnt += right + 1;
        }
        loc *= 10;
    }
    printf("%d", cnt);
}